/**
 * 
 */
package com.wsd.service.impl;

import java.util.Date;
import java.util.List;

import com.wsd.bean.Articles;
import com.wsd.dao.ArticlesDaoInterface;
import com.wsd.service.ArticleService;

/**
 * @author Administrator
 *
 */
public class ArticleServiceImpl implements ArticleService {
	
	private ArticlesDaoInterface articlesDAO;

	public ArticlesDaoInterface getArticlesDAO() {
		return articlesDAO;
	}

	public void setArticlesDAO(ArticlesDaoInterface articlesDAO) {
		this.articlesDAO = articlesDAO;
	}

	public void save(Articles article) {
		articlesDAO.save(article);
	}

	public List<Articles> history(Date startDate, Date endDate, int start, int limit) {
		return articlesDAO.history(startDate,endDate,start,limit);
	}

	public int historyCount(Date startDate, Date endDate) {
		return articlesDAO.historyCount(startDate,endDate);
	}

	/* (non-Javadoc)
	 * @see com.wsd.service.ArticleService#delete(int[])
	 */
	public void delete(int[] ids) {
		for(int id : ids){
			articlesDAO.delete(id);
		}
	}

	/* (non-Javadoc)
	 * @see com.wsd.service.ArticleService#findById(java.lang.Integer)
	 */
	public Articles findById(Integer id) {
		// TODO Auto-generated method stub
		return articlesDAO.findById(id);
	}

	/* (non-Javadoc)
	 * @see com.wsd.service.ArticleService#update(com.wsd.bean.Articles)
	 */
	public void update(Articles preArticle) {
		articlesDAO.update(preArticle);
	}

	/* (non-Javadoc)
	 * @see com.wsd.service.ArticleService#getArticles(com.wsd.bean.Articles, int, int)
	 */
	public List<Articles> getArticles(Articles article, int start, int limit) {
		List<Articles> articles = null;
		if(article.getAModel() == null){
			articles = articlesDAO.findAll(start,limit);
		}else{
			articles = articlesDAO.findAll(article,start,limit);
		}
		return articles;
	}

	/* (non-Javadoc)
	 * @see com.wsd.service.ArticleService#getArticlesCount(com.wsd.bean.Articles)
	 */
	public int getArticlesCount(Articles article) {
		int count = 0;
		if(article.getAModel() == null){
			count = articlesDAO.findAllCount();
		}else{
			count = articlesDAO.findAllCount(article);
		}
		return count;
	}

	/* (non-Javadoc)
	 * @see com.wsd.service.ArticleService#findByModel(int, int, int)
	 */
	public List<Articles> findByModel(int start, int pagesize, int model) {
		return articlesDAO.findByModel(start, pagesize, model);
	}
}
